package webserver;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.*;
import java.net.*;
import java.util.*;

public final class WebServer {
	public static void main(String argv[]){
		ServerSocket serverSocket = null;
		// Set the port number.
		int port = 6789;
		boolean bool = true;
		try {
			// Establish the listen socket.
			serverSocket = new ServerSocket(port);
			// Process HTTP service requests in an infinite loop.
			while (bool) {
				// Listen for a TCP connection request.
				System.out.println("Listening....");
				// Construct an object to process the HTTP request message.
				HttpRequest request = new HttpRequest(serverSocket.accept());
				// Create a new thread to process the request.
				Thread thread = new Thread(request);
				// Start the thread.
				thread.start();
			}
			serverSocket.close();
		} catch (IOException e) {
			// IOException if port is already in use or for another reason.
			System.err.println("Could not listen on port.");
			System.exit(-1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}